;define(function (require) {
	'use strict';
	var $=require('jquery')
		,layer=require('layer')
		,echarts=require('echarts');
		
		require('slide');
		require('touchSlide');
		require('slimscroll');
	
	function app(){}
	app.prototype={
		init:function(){
			//loading
			layer.load(1);
			
			var that = this;
			this.pageSize = this.getPageSize();
			
			//banner
			var $JsBanner = $('#JsBanner')
				,$img = $JsBanner.find('.bd img')
				,len = $img.length
				,_html = '';
			//圆点生成
			for(var i=0;i<len;i++){
				_html = _html + '<li><span class="fa fa-circle"></span></li>';
			}
			$JsBanner.find('.hd').append(_html);
			//轮播
			TouchSlide({
				slideCell:"#JsBanner",
				autoPlay:true,
				startFun:function(i){
					//标题切换
					var _title = $JsBanner.find('.bd img').eq(i).attr('title')
						,_link = $JsBanner.find('.bd a').eq(i).attr('href')
					_html = '<a href="'+_link+'">'+_title+'</a>';
					$JsBanner.find('.hdbox .title').empty().append(_html);
				}
			});
			
			//排名
			var colorArrNum = ['#fa6667','#f49d05','#48a5db','#88d895','#ba99c9'];
			var colorArrTitle = ['#fa6667','#f49d05','#48a5db','#333','#333'];
			var $tr = $('#JsPm').find('tr:gt(0)');
			$tr.each(function(i,e){
				$(e).find('span').css({
					"background":colorArrNum[i]
				})
				$(e).find('div >a').css({
					"color":colorArrTitle[i]
				})
			})
			console.log($tr.length);
			
			//图表
			var cl = ['#b3edf0', '#f9afbf', '#fdf7af', '#e1fbad', '#68d5d5', '#ffd5e7', '#fbd1af', '#e9d3eb', '#ffe9df', '#dadada', '#6ce8b5', '#e28eae'];
			var tmp_series = [{
				name: '累计完成投资额',
				type: 'bar',
				barWidth: '60%',
				data: [10, 52, 200, 334, 390, 330, 220, 110, 52, 120, 86, 99]
			}];
			var tmpArr = [];
			$.each(tmp_series[0].data, function(i, e) {
				//console.log(that.getRemToPxById('chart-font-size'));
				var tmp = {
					name: tmp_series[0].name,
					value: e,
					itemStyle:{
						normal:{
							color: cl[i]
						}
					},
					label:{
						normal:{
							show:true,
							position:'top',
							textStyle:{
								color:'#333',
								fontSize:that.getRemToPxById('chart-font-size')
							}
						}
					}
				};
				tmpArr.push(tmp);
			});
			tmp_series[0].data = tmpArr;
			//console.log(tmp_series);
			var option = {
				title:{
					show:false
				},
				tooltip: {
					trigger: 'axis',
					axisPointer: {
						type: 'shadow'
					}
				},
				grid: {
					left: '3%',
					right: '3%',
					bottom: '3%',
					top:'15%',
					containLabel: true
				},
				xAxis: [{
					type: 'category',
					data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
					axisLine:{
						lineStyle:{
							color:'#79a7e8'
						}
					},
					axisTick: {
						show:false,
						alignWithLabel: true
					},
					axisLabel:{
						textStyle:{
							color:'#333'
						}
						,interval :0
						//,rotate :45
					}
				}],
				yAxis: [{
					type: 'value',
					axisLine:{
						lineStyle:{
							color:'#79a7e8'
						}
					},
					axisTick: {
						show:false
					},
					axisLabel:{
						textStyle:{
							color:'#333'
						}
					},
					splitLine:{
						show:false
					},
					splitArea:{
						show:true,
						areaStyle:{
							color:['#fff','#f7f8f8']
						}
					}
				}],
				label:{
					normal:{
						formatter:'{c}亿元'
					},
					emphasis:{
						formatter:'{c}亿元'
					}
				},
				series: tmp_series
			};
			if($('#chart').length>0){
				var myChart = echarts.init($('#chart')[0]);
				myChart.setOption(option);
			}
			
			
			//loading end
			setTimeout(function(){
				layer.closeAll('loading');
				$('#loadBg').remove();
			}, 800);
			
			/*$('.fm-page-3').slide({
				autoPlay:true,
				effect:"fade",
				interTime:3000,
				mouseOverStop:false,
				trigger:'click'
			})*/
			
		}
		
		,getRemToPxById:function(id){
			return parseFloat($('#'+id).css('font-size'))
		}
		
		//动画生成
		,addAnimate:function(params){
			var that = this,
			 	$obj = params.obj,
			 	po = $obj.attr('anim').length>0 ? eval('('+$obj.attr('anim')+')') : {},
				zidx = po.zidx?po.zidx:1,                         //z-index
				name = po.name,                         //animation-name
				delay = po.delay,                       //animation-delay
				duration = po.duration?po.duration:1,                 //animation-duration
				fun = po.fun?po.fun:'linear',       //animation-timing-function
				count = po.count?po.count:1,        //animation-iteration-count
				fill = po.fill?po.fill:'';       //fill-mode       
			//使用循序时间
			delay = params.dtime?params.dtime:0;
			//使用随机效果
			var animate_styles = ['bounceIn',
			'bounceInLeft','bounceInRight','fadeIn','fadeInLeft',
			'fadeInLeftBig','fadeInRight','fadeInRightBig','lightSpeedIn',
			'rollIn','zoomIn','zoomInDown','zoomInLeft','zoomInRight'];
			var as_len = animate_styles.length;
			function GetRandomNum(Min,Max){
				var Range = Max - Min;
				var Rand = Math.random();
				return(Min + Math.round(Rand * Range));
			}
			var aidx = GetRandomNum(0,as_len-1);
			var ardxg = name?name:animate_styles[aidx];
			//随机效果end
			
			//取出原先style
			var _styles = $obj.attr("append-style");
			if(_styles){
				_styles = $obj.clone().attr("append-style");
			}else{
				_styles = '';
			}
			if(($obj.attr('stop') && $obj.attr('stop')=="false") || (typeof $obj.attr('stop') == 'undefined')){
				$obj.removeAttr("style").removeClass('animated hidden');
				$obj.find('*').removeClass('hidden');
				//重新动画
				//setTimeout(function(){
					$obj.stop(true,false).addClass('animated').attr('style',
					//'visibility:visible;animation-name:'+name+';-webkit-animation-name:'+name
					'visibility:visible;animation-name:'+ardxg+';-webkit-animation-name:'+ardxg
					+';animation-delay:'+delay+';-webkit-animation-delay:'+delay
					+'s;animation-duration:'+duration+'s;-webkit-animation-duration:'+duration+'s;z-index:'+zidx
					+';animation-timing-function:'+fun+';-webkit-animation-timing-function:'+fun
					+';animation-iteration-count:'+count+';-webkit-animation-iteration-count:'+count
					+';animation-fill-mode:'+fill+';-webkit-animation-fill-mode:'+fill+';'+_styles);
				//}, 10);
			}else{
				$obj.stop(true,false).attr("stop",false);
			}
			return delay+duration;
		}
		
		,getPageSize:function(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight}}var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth}else{windowWidth=self.innerWidth}windowHeight=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else{if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}}}if(yScroll<windowHeight){var pageHeight=windowHeight}else{var pageHeight=yScroll}if(xScroll<windowWidth){var pageWidth=xScroll}else{var pageWidth=windowWidth}var arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize}
	}
	return app;
})

